@()

@widgets.dialog(title = "Import Project", submitLabel = "Import") {

  <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
    <input class="mdl-textfield__input" type="text" id="project_name" name="project_name"/>
    <label class="mdl-textfield__label" for="project_name">Name</label>
  </div>
  <div>
    <input name="file" type="file"/>
  </div>

  <script>//<![CDATA[

    function submit() {
      var name = $("input[name='project_name']").val();
      var file = $("input[name='file']").val();
      var formData = new FormData($('form')[0]);

      $("#dialog-progress-spinner").show();
      $("#dialog-submit-button").prop("disabled", true);

      $.ajax({
        type: 'POST',
        url: '@config.baseUrl/workspace/projects/' + name + '/import',
        xhr: function() {  // custom xhr
            myXhr = $.ajaxSettings.xhr();
            return myXhr;
        },
        data: formData,
        cache: false,
        contentType: false,
        processData: false,
        success: function(data) {
          $("#dialog-progress-spinner").hide();
          $("#dialog-submit-button").prop("disabled", false);
          closeDialog();
          reloadWorkspace();
        },
        error: function(request) {
          $("#dialog-progress-spinner").hide();
          $("#dialog-submit-button").prop("disabled", false);
          alert(request.responseText);
        }
      });
    }
  //]]>
  </script>
}